import {
	ref
} from 'vue';
import {
	getopenId
} from '@/api/openid.js';

export const WxLogin = () => {
	let appid = 'wxeecaca9bcc4c4318';
	let secret = 'ec7d2761f2b78e1e8c6f8d6a07fe76a8';
	let promise = new Promise((resolve, reject) => {
		wx.login({
			success: (res) => {
				resolve(res.code);
			},
			fail(error) {
				reject(error);
			},
		});
	});
	return promise;
};

export const getWxopenid = async () => {
	let CodeValue = ref(null);
	console.log('正在登录到微信官方接口获取Code...');
	CodeValue.value = await WxLogin();
	console.log('当前微信登录成功,CodeValue.value:', CodeValue.value);
	let res = await getopenId({
		code: CodeValue.value,
	});
	console.log('获取到wxopenid', res.data);
	return res;
};